﻿/* ************************************************************
 * Namespace: JumpFleetGameLib.xMap.SectorMap
 * Class:  ObjectLayer
 * Author:  Roy Penrod
 * 
 * Class to organize the object layers in a sector map.  
 * Each layer contains a collection of IPositionableObject
 * objects.
 *  
 * ************************************************************ */

using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;


namespace JumpFleetGameLib.xMap.SectorMap
{
    public class ObjectLayer
    {
        #region MEMBERS

        // tag to identify the layer
        private string _tag;

        // depth the tiles in this layer will be drawn at
        private float _depth;

        // holds the IPositionableObject objects
        public List<IPositionableObject> PositionableObjectList;                

        // flag for whether the layer is visible or not
        private bool _visible;        

        // current position of the map origin
        private Vector2 _currentMapPosition;

        #endregion


        #region PROPERTIES

        /// <summary>
        /// Tag to identify the object layer.  Type: string
        /// </summary>
        public string Tag
        {
            get { return _tag; }

            set { _tag = value; }
        }       

        /// <summary>
        /// Depth the tiles in this layer will be drawn at.  Sets the Layer property for each IPositionableObject.  Type: float
        /// </summary>
        public float Depth
        {
            get { return _depth; }
            set 
            {
                _depth = value;
                SetPositionableObjectDepth();  
            }
        }
        
        /// <summary>
        /// Flag for whether this object layer is visible.  Sets the Visible property for each IPositionableObject.  Type: bool
        /// </summary>
        public bool Visible
        {
            get { return _visible; }
            set 
            {
                _visible = value;
                SetPositionableObjectVisible();
            }
        }

        /// <summary>
        /// Current position of the map origin.  Sets the CurrentMapPosition property for each IPositionableObject.  Type: Vector2
        /// </summary>
        public Vector2 CurrentMapPosition
        {
            get { return _currentMapPosition; }

            set 
            { 
                _currentMapPosition = value;
                SetCurrentMapPosition();
            }
        }

        #endregion


        #region CONSTRUCTORS

        // _visible defaults to false
        /// <summary>
        /// Constructor for the ObjectLayer class.  The Visible property defaults to false.
        /// </summary>
        /// <param name="tag">Tag to identify the object layer.  Type: string</param>       
        /// <param name="layerDepth">Depth the IPositionableObject objects in this layer will be drawn at.  Type: float</param>        
        public ObjectLayer(string tag, float layerDepth)
        {
            // assigns the parameters
            _tag = tag;
            _depth = layerDepth;     
       
            // creates the PositionableObjectsList
            PositionableObjectList = new List<IPositionableObject>();
        }

        #endregion


        #region METHODS
        
        /// <summary>
        /// Sets the Layer property of each IPositionableObject to the Depth property of this Layer object.
        /// </summary>
        private void SetPositionableObjectDepth()
        {
            // go through the PositionableObjectsList and set the Layer
            // property of each IPositionableObject to the Depth property
            // of this Layer object
            foreach (IPositionableObject positionableObject in PositionableObjectList)
                positionableObject.Layer = Depth;
        }

        /// <summary>
        /// Sets the Visible property of each IPositionableObject to the Visible property of this Layer object.
        /// </summary>
        private void SetPositionableObjectVisible()
        {
            // go through the PositionableObjectsList and set the 
            // Visible property of each IPositionableObject to the 
            // Visible property of this Layer object
            foreach (IPositionableObject positionableObject in PositionableObjectList)
                positionableObject.Visible = Visible;
        }

        /// <summary>
        /// Sets the CurrentMapPosition property of each IPositionableObject to the CurrentMapPosition property of this Layer object.
        /// </summary>
        private void SetCurrentMapPosition()
        {
            // go through the PositionableObjectsList and set the
            // CurrentMapPosition of each IPositionableObject to the
            // CurrentMapPosition property of this Layer object
            foreach (IPositionableObject positionalObject in PositionableObjectList)
                positionalObject.CurrentMapPosition = CurrentMapPosition;
        }

        #endregion

    } // <-- end class
} // <-- end namespace
